package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC565 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int arrayNesting(int[] arr) {
            boolean[] visited = new boolean[arr.length];
            int maxLength = 0;
            for (int i = 0; i < arr.length; i++) {
                int cur = i, curLength = 0;
                while (!visited[cur]) {
                    visited[cur] = true;
                    cur = arr[cur];
                    ++curLength;
                }
                maxLength = Math.max(maxLength, curLength);
            }

            return maxLength;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[5,4,0,3,1,6,2]");
        System.out.println(solution.arrayNesting(arr));
    }

    public static void main(String[] args) throws Exception {
        LC565 an = new LC565();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
